using System;
using System.Windows.Forms;
using System.Drawing;

public class DGVFileCell : DataGridViewTextBoxCell
{
    DGVFileEditingControl filecontrol = new DGVFileEditingControl();

    public DGVFileCell()
        : base()
    {
    }

    public override void InitializeEditingControl(int rowIndex, object
        initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
    {
        // Set the value of the editing control to the current cell value.
        base.InitializeEditingControl(rowIndex, initialFormattedValue,
            dataGridViewCellStyle);

        filecontrol = DataGridView.EditingControl as DGVFileEditingControl;

        if (initialFormattedValue == null || (string)initialFormattedValue == "")
            filecontrol.Value = "";
        else
            filecontrol.Value = (string)initialFormattedValue;
    }

    public override Type EditType
    {
        get
        {
            return typeof(DGVFileEditingControl);
        }
    }

    protected override Size GetPreferredSize(Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize)
    {
        try
        {
            if (this.IsInEditMode)
                return filecontrol.Size;
            else
                return base.GetPreferredSize(graphics, cellStyle, rowIndex, constraintSize);
        }
        catch
        {
            return base.GetPreferredSize(graphics, cellStyle, rowIndex, constraintSize);
        }
    }

/*    public override object Clone()
    {
        FileControlCell cell = base.Clone() as FileControlCell;

        if (cell != null)
            cell.FileControl = this.FileControl;

        return cell;
    }*/
}
